package com.itboye.textlieexpters.webview;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.itboye.textileexpres.R;
import com.itboye.textileexpres.base.BaseActivity;

public class WebSetActivity extends BaseActivity implements OnClickListener {
	ProgressBar pb;
	WebView webView = null;
	private String urlTitle;
	private String url;
	private ImageView img_other, back;
	private TextView title;
	ProgressDialog dialog = null;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.avtivity_webview;
	}

	@SuppressLint("SetJavaScriptEnabled")
	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		pb = (ProgressBar) findViewById(R.id.pb);
		pb.setMax(100);
		url = getIntent().getStringExtra("url");
		urlTitle = getIntent().getStringExtra("title");
		title.setText(urlTitle);
		img_other.setVisibility(View.GONE);
		webView = (WebView) findViewById(R.id.webview);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.getSettings().setSupportZoom(true);
		webView.getSettings().setBuiltInZoomControls(true);
		if (webView != null) {
			webView.setWebChromeClient(new WebViewClient());
		}

		// webView.loadUrl(url);
		onLaodUrl(url);
	}

	public void onLaodUrl(String url) {
		if (webView != null) {
			webView.loadUrl(url);
			dialog = ProgressDialog.show(WebSetActivity.this, null, "页面加载中...");
			webView.reload();

		}
	}

	private class WebViewClient extends WebChromeClient {

		@Override
		public void onProgressChanged(WebView view, int newProgress) {
			dialog.dismiss();
			
			pb.setProgress(newProgress);
			if (newProgress == 100) {
				pb.setVisibility(View.GONE);
			}
			super.onProgressChanged(view, newProgress);
		}
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.back:
			this.finish();
			break;

		default:
			break;
		}
	}

}
